<?php
//+---------------
//|控制器
//+--------------
class Controller {
	
	public $smarty;
	/**
	 * 显示模版
	 * @see IController::View()
	 */
	public function View(){		
		include("CleverPHP/View/Smarty/Smarty.class.php");		
		$this->smarty=new Smarty();		
		$smarty_config=C("smarty_config");		
        $this->smarty->template_dir=$smarty_config["template_dir"];      
        $this->smarty->compile_dir=$smarty_config["compile_dir"];       
        $this->smarty->config_dir=$smarty_config["config_dir"];      
        $this->smarty->cache_dir=$smarty_config["cache_dir"];      
        $this->smarty->caching=$smarty_config["caching"];      
        $this->smarty->left_delimiter=$smarty_config["left_delimiter"];      
        $this->smarty->right_delimiter=$smarty_config["right_delimiter"]; 
        $this->smarty->registerPlugin("function","__URL__","getURL");	
        $this->smarty->registerPlugin("function","Config","C");
	}  
    /**
     * 输出信息
     * @see IController::success()
     */
	public function message($data=array(),$ajax=false,$type="success"){		 
		 $this->View();			  
		 if($ajax==false){
		 	 //标题
		 	 array_key_exists("title",$data)?$title=$data["title"]:$title=null;
		 	 $this->smarty->assign("title",$title);
		 	 //信息内容
		 	 array_key_exists("message", $data)?$message=$data["message"]:$message=null;
		 	 $this->smarty->assign("message",$message);
		 	 //转向  
		 	 array_key_exists("url", $data)?$url=$data["url"]:$url=$_SERVER["HTTP_REFERER"];
		 	 //转向时间
		 	 array_key_exists("times", $data)?$times=$data["times"]:$times=1;
		 	 $this->smarty->assign("times",$times);
		 	 $this->smarty->assign("url",$url);		 	   
		 	 if ($type=="success"){
		 	 	$this->smarty->display('success.html');
		 	 }else{
		 	 	$this->smarty->display('error.html');
		 	 }		 	  		 	
		 }else {
		 	$this->ajaxReturn($data, 1,"json");
		 }  
		 exit(0);		
		
	}
	/**
	 * ajax返回
	 * Enter description here ...
	 * @param unknown_type $data
	 * @param unknown_type $info
	 * @param unknown_type $type
	 */
	public function  ajaxReturn($data=array(),$status,$type="xml"){
		if (array_key_exists("title", $data))
			  $datas["title"]=$data["title"];
		if (array_key_exists("message", $data))
			  $datas["message"]=$data["message"];
		$datas["status"]=$status;
		if ($type=="json"){	
			//输出json					
			header("Content-Type:text/html; charset=utf-8");
			exit(json_encode($datas));
		}elseif ($type=="xml"){
			//输出xml
			header("Content-Type:text/xml; charset=utf-8");
			exit(xml_encode($datas));
		}
	}
	
	
}
?>